'use strict'
const moment = require('moment')
module.exports = {
  test() {
    this.app.io.of('/')
    return 'as'
  },
  createSealNum() {
    return Date.now().toString().slice(-8) + Math.random().toString().slice(-4)
  },
  sortList(list, pid = 0) {
    const tree = []
    let temp = []
    list.forEach(item => {
      if (item.pid == pid) {
        const obj = item.get({ plain: true })
        obj.children = []
        temp = this.sortList(list, item.id)
        if (temp.length > 0) {
          obj.children = temp
        }
        tree.push(obj)
      }
    })
    return tree
  },
  // 判断分数和状态
  handleStatus(currentScore, changeScore, type) {
    let newScore
    const data = { status: '', wz_score: 0 }
    if (type === 'add') newScore = currentScore + changeScore
    else {
      newScore = currentScore - changeScore
      if (currentScore > 0 && newScore <= 0) data.black_at = new Date()
    }

    if (newScore <= 0) {
      data.status = 'RED'
      data.wz_score = newScore
    } else if (newScore < 12) {
      data.status = 'ORANGE'
      data.wz_score = newScore
    } else {
      data.status = 'GREEN'
      data.wz_score = 12
    }
    return data
  },
}
